package com.demo;

import com.spring.annotation.Component;
import com.web.HandlerInterceptor;
import com.web.WebHandler;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * @author chengjy
 * @date 2025/4/15
 */
@Component
public class LoggerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, WebHandler webHandler) {
       System.out.println("请求执行前记录日志:" + request.getRequestURI());
       return HandlerInterceptor.super.preHandle(request, response, webHandler);
    }

    @Override
    public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object result) {
        System.out.println("请求执行后记录日志:" + request.getRequestURI());
        return HandlerInterceptor.super.postHandle(request, response, result);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, WebHandler webHandler) {
        System.out.println("请求最终返回前记录日志:" + request.getRequestURI());
        HandlerInterceptor.super.afterCompletion(request, response, webHandler);
    }
}
